package com.zk.monitormanagement.app;

import android.app.Application;
import android.content.Context;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.cache.CacheEntity;
import com.lzy.okgo.cache.CacheMode;
import com.lzy.okgo.interceptor.HttpLoggingInterceptor;
import com.videogo.openapi.EZOpenSDK;

import java.util.logging.Level;

import okhttp3.OkHttpClient;

/**
 * @author Created by zhangke
 * @filename MyApplication
 * @date on 2018\12\19 0019 21:35
 * @email 206357792@qq.com
 * @describe TODO
 */

public class MyApplication extends Application {
    private static final String APP_KEY ="03a37053f53448509651c66c82212311" ;
    private static MyApplication instance;

    public static synchronized MyApplication getInstance() {
        return instance;
    }

    private static Context mContext;

    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        mContext = base;
    }


    public static EZOpenSDK getOpenSDK() {
        return EZOpenSDK.getInstance();
    }

    public static Context getContext() {
        return mContext;
    }
    @Override
    public void onCreate() {
        super.onCreate();
        instance=this;
        /** * sdk日志开关，正式发布需要去掉 */
        EZOpenSDK.showSDKLog(true);
          /** * 设置是否支持P2P取流,详见api */
        EZOpenSDK.enableP2P(false);

        /** * APP_KEY请替换成自己申请的 */
        EZOpenSDK.initLib(this, APP_KEY);

        OkHttpClient.Builder builder=new OkHttpClient.Builder();
        //log相关
        HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("OkGo");
        loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);        //log打印级别，决定了log显示的详细程度
        loggingInterceptor.setColorLevel(Level.INFO);                               //log颜色级别，决定了log在控制台显示的颜色
        builder.addInterceptor(loggingInterceptor);
        OkGo.getInstance().init(this)                       //必须调用初始化
                .setOkHttpClient(builder.build())               //建议设置OkHttpClient，不设置将使用默认的
                .setCacheMode(CacheMode.NO_CACHE)               //全局统一缓存模式，默认不使用缓存，可以不传
                .setCacheTime(CacheEntity.CACHE_NEVER_EXPIRE)   //全局统一缓存时间，默认永不过期，可以不传
                .setRetryCount(3);                              //全局统一超时重连次数，默认为三次，那么最差的情况会请求4次(一次原始请求，三次重连请求)，不需要可以设置为0
//                .addCommonHeaders(headers)                      //全局公共头
//                .addCommonParams(params);                       //全局公共参数
    }
}
